#include "OgreApplicationFrameListener.h"
#include "BoneSet.h"

OgreApplicationFrameListener::OgreApplicationFrameListener(SceneManager* sceneManager, RenderWindow* window, Camera *cam)
: StandardFrameListener(window, cam)
{
	_sceneManager = sceneManager;
	_spiderMngr = SpiderManager::getSingletonPtr();
	elapsedTime = 0;
}

//------------------------------------------------------

bool OgreApplicationFrameListener::frameStarted(const FrameEvent& evt)
{
	elapsedTime += evt.timeSinceLastFrame; 
	//BoneSet::timer = elapsedTime;
	
	
	_spiderMngr->updateBones(evt.timeSinceLastFrame);
	return true;
}

//------------------------------------------------------
bool OgreApplicationFrameListener::frameEnded(const FrameEvent& evt)
{
	return StandardFrameListener::frameEnded(evt);	
}

//------------------------------------------------------

bool OgreApplicationFrameListener::processUnbufferedKeyInput(const Ogre::FrameEvent &evt)
{
	
	if(mKeyboard->isKeyDown(OIS::KC_K))
	{	
		BoneSet::timer -= 0.04;
		_spiderMngr->getSpiderSceneNode()->translate(Vector3(0,0,-evt.timeSinceLastFrame));
	}
	if(mKeyboard->isKeyDown(OIS::KC_I))
	{
		BoneSet::timer += 0.04;
		_spiderMngr->getSpiderSceneNode()->translate(Vector3(0,0,evt.timeSinceLastFrame));
	}
	return StandardFrameListener::processUnbufferedKeyInput(evt);
}
